<?php

namespace Dao\Kv;

class Captchacode {

    const PHPLIB_SMS_CODE_PREFIX = 'captcha_';
    const DEFAULT_TTL = '3600';

    private static $redis = null;

    private static function getInstance() {
        if (is_null(self::$redis)) {
            self::$redis = new \S\Db\Redis();
        }
        return self::$redis;
    }

    /**
     * @param $key
     * @return mixed
     */
    public static function get($key) {
        return self::getInstance()->get(self::PHPLIB_SMS_CODE_PREFIX . $key);
    }

    /**
     * @param $key
     * @param $value
     * @param $ttl
     * @return mixed
     */
    public static function set($key, $value, $ttl = self::DEFAULT_TTL) {
        return self::getInstance()->set(self::PHPLIB_SMS_CODE_PREFIX . $key, $value, $ttl);
    }

    /**
     * @param $key
     * @return mixed
     */
    public static function incr($key) {
        return self::getInstance()->incr(self::PHPLIB_SMS_CODE_PREFIX . $key);
    }

    /**
     * @param $key
     * @return mixed
     */
    public static function del($key) {
        return self::getInstance()->del(self::PHPLIB_SMS_CODE_PREFIX . $key);
    }

    /**
     * @param $key
     * @param $seconds
     * @return mixed
     */
    public static function expire($key, $seconds) {
        return self::getInstance()->expire(self::PHPLIB_SMS_CODE_PREFIX . $key, $seconds);
    }

}